trait BaseIM {
    fn open(&self);
    fn close(&self);
    fn error(&self, err: String);
    fn send(&self, payload: String);
}

trait IM: BaseIM {
    fn version(&self) -> String;
}

struct VideoIM;

impl BaseIM for VideoIM {
    fn open(&self) {
        println!("VideoIM 开始播放视频");
    }

    fn close(&self) {
        println!("VideoIM 关闭视频");
    }

    fn error(&self, err: String) {
        println!("VideoIM 出现错误: {}", err);
    }

    fn send(&self, payload: String) {
        println!("VideoIM 发送数据: {}", payload);
    }
}

impl IM for VideoIM {
    fn version(&self) -> String {
        "1.0.0".to_string()
    }
}

// 实现多态

trait Person {
    fn eat(&self);
}

struct Boy;
struct Gril;

impl Person for Boy {
    fn eat(&self) {
        println!("男孩从吃饭");
    }
}

impl Person for Gril {
    fn eat(&self) {
        println!("女孩从吃饭");
    }
}

fn display_eat(p: &dyn Person) {
    p.eat();
}

fn main() {
    let video_im = VideoIM;

    video_im.open();
    video_im.send("播放视频数据".to_string());
    video_im.error("视频加载失败".to_string());
    video_im.close();

    println!("VideoIM 版本: {}", video_im.version());

    let jack = Boy;
    let marry = Gril;
    display_eat(&jack);
    display_eat(&marry);
}
